home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Griffith 0.9.8 / griffith-0.9.8-win32.exe / {app} / lib / plugins / movie / PluginMovieFilmweb.py < prev    next >
Text File  |  2008-11-17  |  7KB  |  181 lines

  1. # -*- coding: utf-8 -*-
  2.  
  3. __revision__ = '$Id: PluginMovieFilmweb.py 1040 2008-11-15 21:13:49Z mikej06 $'
  4.  
  5. # Copyright (c) 2005-2007 Piotr O┼╝arowski
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  20.  
  21. # You may use and distribute this software under the terms of the
  22. # GNU General Public License, version 2 or later
  23.  
  24. import gutils, movie
  25. import re,string
  26.  
  27. plugin_name        = 'Filmweb'
  28. plugin_description    = 'Web pe┼éen film├│w'
  29. plugin_url        = 'www.filmweb.pl'
  30. plugin_language        = _('Polish')
  31. plugin_author        = 'Piotr O┼╝arowski'
  32. plugin_author_email    = '<ozarow+griffith@gmail.com>'
  33. plugin_version        = '1.12'
  34.  
  35. class Plugin(movie.Movie):
  36.     TRAILER_PATTERN     = re.compile("""<a class=["']notSelected["'].*?href=["'](.*?)["']>zwiastuny</a>\s*\[\d+\]\s*»""")
  37.     DIRECTOR_PATTERN    = re.compile('yseria\s+(.*)\s+scenariusz', re.MULTILINE)
  38.     O_TITLE_AKA_PATTERN = re.compile('\(AKA\s+(.*?)\)')
  39.  
  40.     def __init__(self, id):
  41.         self.movie_id = 'filmweb'
  42.         self.url      = str(id)
  43.         self.encode   = 'utf-8'
  44.  
  45.     def get_image(self):
  46.         if string.find(self.page,'<div class="film-poster">') > -1:
  47.             self.image_url = gutils.trim(self.page, 'rel="artshow" href="', '">')
  48.         else:
  49.             self.image_url = ''
  50.  
  51.     def get_o_title(self):
  52.         self.o_title = gutils.trim(self.page, '<title>', '</title>')
  53.         if string.find(self.o_title, '/') > -1:
  54.             self.o_title = gutils.trim(self.o_title, '/', '(')
  55.         if string.find(self.o_title, '(') > -1:
  56.             self.o_title = gutils.before(self.o_title, '(')
  57.  
  58.     def get_title(self):
  59.         self.title = gutils.trim(self.page, '<title>', '</title>')
  60.         if string.find(self.title, '(') > -1:
  61.             self.title = gutils.before(self.title, '(')
  62.         if string.find(self.title, '/') > -1:
  63.             self.title = gutils.before(self.title, '/')
  64.             
  65.     def get_director(self):
  66.         director = self.DIRECTOR_PATTERN.findall(self.page)
  67.         if len(director)>0:
  68.             self.director = director[0]
  69.             self.director = string.replace(self.director, "\t",'')
  70.             self.director = re.sub('\s+', ' ', self.director)
  71.             self.director = string.replace(self.director, ",",", ")
  72.             self.director = string.replace(self.director, "  "," ")
  73.             self.director = string.replace(self.director, " ,  ",", ")
  74.             self.director = string.replace(self.director, ",  (wi\xeacej ...)",'')
  75.  
  76.     def get_plot(self):
  77.         self.plot = gutils.trim(self.page,'<h2 id="o-filmie-header" class="replace">','</div>')
  78.         self.plot = gutils.after(self.plot, '<p>')
  79.         url = gutils.trim(self.plot,"\t...","</a>")
  80.         url = gutils.trim(url, 'href="','"')
  81.         self.plot = gutils.strip_tags(self.plot)
  82.         if url != '':
  83.             plot_page = self.open_page(url=url)
  84.             self.plot = gutils.trim(plot_page, '<div class="filmContent">', '</ul>')
  85.             self.plot = gutils.after(self.plot, 'zg┼éo┼¢ poprawk─Ö')
  86.  
  87.     def get_year(self):
  88.         self.year = gutils.trim(self.page, '<span class="year">', '</a>')
  89.  
  90.     def get_runtime(self):
  91.         self.runtime = gutils.trim(self.page,"\tczas trwania: ","\n")
  92.  
  93.     def get_genre(self):
  94.         self.genre = gutils.trim(self.page,"\tgatunek:", '</p>')
  95.         self.genre = string.replace(self.genre, "\t",'')
  96.         self.genre = string.replace(self.genre, "\n",'')
  97.  
  98.     def get_cast(self):
  99.         self.cast = gutils.trim(self.page, '<td class="film-actor">',"zobacz wi─Öcej")
  100.         self.cast = string.replace(self.cast, chr(13),"")
  101.         self.cast = string.replace(self.cast, chr(10),"")
  102. #        self.cast = string.replace(self.cast, "\n","")
  103.         self.cast = string.replace(self.cast, "\t",'')
  104.         self.cast = string.replace(self.cast, "  ",'')
  105.         self.cast = string.replace(self.cast, '<td class="film-protagonist">', _(" as "))
  106.         self.cast = string.replace(self.cast, '</tr>',"\n")
  107.         self.cast = gutils.strip_tags(self.cast)
  108.  
  109.     def get_classification(self):
  110.         self.classification = gutils.trim(self.page,"\tod lat: ","\t")
  111.         self.classification = string.replace(self.classification, "\t",'')
  112.         self.classification = string.replace(self.classification, "\n",'')
  113.  
  114.     def get_studio(self):
  115.         self.studio = ''
  116.  
  117.     def get_o_site(self):
  118.         self.o_site = ''
  119.  
  120.     def get_site(self):
  121.         self.site = self.url
  122.  
  123.     def get_trailer(self):
  124.         trailer = self.TRAILER_PATTERN.findall(self.page)
  125.         if trailer:
  126.             self.trailer = trailer[0]
  127.  
  128.     def get_country(self):
  129.         self.country = gutils.trim(self.page,"\tprodukcja:", '</strong>')
  130.         self.country = string.replace(self.country, "\t",'')
  131.  
  132.     def get_rating(self):
  133.         self.rating = gutils.trim(self.page, '\t<span><strong class="value">', '</strong>')
  134.         if self.rating != '':
  135.             self.rating = string.replace(self.rating, ',', '.')
  136.             self.rating = str( float(string.strip(self.rating)) )
  137.  
  138.     def get_notes(self):
  139.         self.notes = ''
  140.  
  141. class SearchPlugin(movie.SearchMovie):
  142.     def __init__(self):
  143.         self.encode='utf-8'
  144.         self.original_url_search   = "http://www.filmweb.pl/szukaj?c=film&q="
  145.         self.translated_url_search = "http://www.filmweb.pl/szukaj?c=film&q="
  146.  
  147.     def search(self,parent_window):
  148.         self.open_search(parent_window)
  149.         pos = string.find(self.page, 'Znaleziono <b>')
  150.         if pos == -1:    # movie page
  151.             self.page = None
  152.         else:        # search results
  153.             items = gutils.trim(self.page[pos:], '<b>', '</b>')
  154.             if items == '0':
  155.                 self.page = False
  156.             else:
  157.                 self.page = gutils.before(self.page[pos:], 'id="sitemap"')
  158.                 self.page = gutils.after(self.page, '<li ')
  159.         return self.page
  160.  
  161.     def get_searches(self):
  162.         if self.page is None:    # movie page
  163.             self.number_results = 1
  164.             self.ids.append(self.url)
  165.             self.titles.append(gutils.convert_entities(self.title))
  166.         elif self.page is False: # no movie found
  167.             self.number_results = 0
  168.         else:            # multiple matches
  169.             elements = string.split(self.page, '<li ')
  170.             self.number_results = elements[-1]
  171.             if (elements[0]<>''):
  172.                 for element in elements:
  173.                     element = gutils.after(element, '<a class="searchResultTitle" href="')
  174.                     self.ids.append(gutils.before(element, '">'))
  175.                     element = gutils.trim(element, '">', '</a>')
  176.                     element = gutils.convert_entities(element)
  177.                     element = gutils.strip_tags(element)
  178.                     self.titles.append(element)
  179.             else:
  180.                 self.number_results = 0
  181.